<?php 
$this->pageTitle='Tài khoản - '.$model->username; 

$show=Tools::is3G();
?>
<div class="title_mod">
	<a href="#" title="Tài khoản"><span class="mleft"><span class="mright">Tài khoản</span></span></a>
</div>
<div class="form">
	<div class="row">
	<?php
	    foreach(Yii::app()->user->getFlashes() as $key => $message) {
	        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
	    }
	?>
	</div>
	<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'changepass-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
		),
	)); ?>
	<div class="row">
		<label>Tên tài khoản:</label>
		<input name="username" type="text" value="<?php echo $model->username;?>" readonly="readonly" />
	</div>
    <div class="row">
        <label>Số điện thoại:</label>
        <input name="amounst" type="text" value="<?php echo ($model->phone_number>0)?($model->phone_number):("Chưa cập nhật");?>" readonly="readonly" />
    </div>
	<div class="row">
		<label>Số dư:</label>
		<input name="amounst" type="text" value="<?php echo ($model->amount/1000).' Xu';?>" readonly="readonly" />
	</div>
	<div class="row">
		<label>Đăng ký</label>
		<?php
		$trans = Transpackage::model ()->findByAttributes ( array ('mid' => Yii::app ()->user->id,),array('order'=>'t.id DESC') );
		$fdate = date_create($trans->startdate);
		$fdate =  date_format($fdate,'H:i d-m-Y');
		?>
		<input name="activedate" type="text" value="<?php echo $fdate;?>" readonly="readonly" />
	</div>
	<div class="row">
		<label>Đến ngày</label>
		<?php 
		$edate = date_create($trans->enddate);
		$edate =  date_format($edate,'H:i d-m-Y');
		?>
		<input name="activedate" type="text" value="<?php echo $edate;?>" readonly="readonly" />
	</div>
	<div class="row buttons">
		<?php if($show!=''):?>
		<?php 
			$Session= new Session('Script');
			$Session->set('fs',time());
			$Session->set('id',time());
			$appid=Yii::app()->params['applicationId'];
			$appsecret=Yii::app()->params['appSecret'];
			$p=$Session->Get('id');
			$s=$Session->Get('fs');
			$md5=md5($appid.$p.$appsecret.$s);
			$link=Yii::app()->params['paymentUrl'].'?a='.$appid.'&p='.$p.'&s='.$s.'&md5='.$md5;
		?>
		<?php echo CHtml::link('Nạp tiền',$link,array('title'=>'Nạp tiền','class'=>'button-get')); ?>
		<?php //echo CHtml::link('Nạp tiền',array('/package'),array('title'=>'Nạp tiền','class'=>'button-get')); ?>
		<?php echo CHtml::link('Thoát',array('/site/logout'),array('title'=>'Thoát','class'=>'button')); ?>
		<?php else:?>
			<?php echo CHtml::link('Thoát',array('/site/logout'),array('title'=>'Thoát','class'=>'button')); ?>
			<div style="text-align: justify;">
			<?php if(isset($package)){echo str_replace('&lt;phone&gt;',Yii::app()->user->username, $package->desc) ;}?>
			</div>
		<?php endif;?>
	</div>
	<!--<div class="row">
		<label>Mật khẩu mới</label>
		<input type="password" value="" name="newpass" id="newpass"/>
		<span id="pass" class="error"></span>
	</div>
	<div class="row">
		<label>Xác nhận mật khẩu mới</label>
		<input type="password" value="" name="repass" id="repass" />
		<span id="cpass" class="error"></span>
	</div>-->
	<div class="row buttons">
		<?php echo CHtml::submitButton('Đổi mật khẩu',array('id'=>'change','style'=>'margin:auto;float:none;')); ?>
	</div>
	<?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
	//$('.form').css('min-height',($(window).height()-117-167)+'px');
	/*var canDetect = "onorientationchange" in window; 
	var orientationTimer = 0; 
	$(window).bind(canDetect ? "orientationchange" : "resize", function(evt) { 
	   clearTimeout(orientationTimer); 
	   orientationTimer = setTimeout(function() {
		   $('.form').css('min-height',($(window).height()-117-167)+'px');
	  }, 500); 
	});*/
	$('#change').click(function(){
		$('#cpass').text('');
		$('#pass').text('');
		return validation();
	});
	function validation(){
		$co=true;
		if($('#newpass').val()==''){
			$('#pass').text('Bạn chưa nhập mật khẩu mới');
			$co=false;
		}
		if($('#repass').val()==''){
			$('#cpass').text('Bạn chưa nhập mật khẩu xác nhận');
			$co=false;
		}
		else if($('#newpass').val() != $('#repass').val()){
			$('#cpass').text('Mật khẩu xác nhận chưa đúng');
			$co=false;
		}
		return $co;
	}
});
</script>
